program example
use polymorphic_complextaylor
implicit none 
integer no,nv,n,i
type(complextaylor) f,g
complex(dp) c, cc
integer, allocatable :: j(:),k(:),jj(:)


no=6; nv= 4;    ! no: the order of the polynomial    nv: the number of variables   
call init(no,nv)  ! initializes taylor series without maps

call alloc(f,g)      ! must be constructed after init



n=2
allocate(j(nv),k(n),jj(nv)) 

j=0
j(1)=1;j(2)=1;j(3)=2;j(4)=1;

jj=0
jj(1)=1;jj(2)=1;jj(3)=0;jj(4)=3;

k=0
do i=1, n
     k(i)=j(i)
end do


c=cmplx(5.d0,-1.4d0,kind=dp)
cc=cmplx(6.d0,1.6d0,kind=dp)  


f=(c.mono.j)  + (cc.mono.jj) + 4.d0
   !  Creates (5.d0 x_1 x_ 2 x_3^2 x_4 - 1.4d0 i* x_1 x_ 2 x_3^2 x_ 4) 
   !                   + (6.d0 x_1 x_ 2  x_ 4^3 +1.6d0 i* x_1 x_ 2  x_ 4^3 )+ 4.d0 
g=f<=k  
   !  Creates (5.d0 x_3^2 x_4 - 1.4d0 i* x_3^2 x_ 4) +( 6.d0  x_ 4^3 + 1.6d0 i*  x_ 4^3)
   !       and shifts exponents downwards by n!

call print(f,6)
call print(g,6)

deallocate(j,k,jj)



f=(c.mono.'2111')  +  (cc.mono.'2112' ) + 6.d0
    !  Creates (5.d0 x_1^2 x_ 2 x_3 x_ 4 - 1.4d0 i* x_1^2 x_ 2 x_3 x_ 4)
	!                   + (6.d0 x_1^2 x_ 2 x_3 x_ 4^2 + 1.6d0 i* x_1^2 x_ 2 x_3 x_ 4^2 )+ 6.d0
g=f<='211' 
    ! Creates (5.d0 x_4 - 1.4d0 i*  x_ 4) +( 6.d0 x_4^2 + 1.6d0 i* x_ 4^2) 
    !      and shifts exponents downwards by '211'(three digits!)

call print(f,6)
call print(g,6)



call kill(f,g)      ! must be destroyed
end program example